unit uFrmShareVehicleFilter;

interface

uses
  SysUtils, Classes, Variants, Windows, Messages, Graphics, Controls, Forms, Dialogs,
  StdCtrls, uDZSysUtils, uCxtConst, uCxtTypes, uCxtForm, uFrmCity, ExtCtrls;

type
  TFrmShareVehicleFilter = class(TBaseForm)
    Panel1: TPanel;
    Label7: TLabel;
    Label8: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    edtDangQianWeiZhi: TEdit;
    edtQiWangLiuXiang: TEdit;
    btnDQCSSel: TButton;
    btnQWLXSel: TButton;
    btnClearDQWZ: TButton;
    btnClearQWLX: TButton;
    btnOK: TButton;
    btnCancel: TButton;
    cbbDunWei: TComboBox;
    edtRongJi: TEdit;
    edtCheGao: TEdit;
    edtCheKuan: TEdit;
    cbbCheZhang: TComboBox;
    edtBeiZhu: TEdit;
    cbbLocate: TComboBox;
    cbbTuoGuaLunZhou: TComboBox;
    cbbHuoXiangJieGou: TComboBox;
    cbbTeShuGongNeng: TComboBox;
    cbbChangShangPinPai: TComboBox;
    procedure btnDQCSSelClick(Sender: TObject);
    procedure btnClearDQWZClick(Sender: TObject);
    procedure btnClearQWLXClick(Sender: TObject);
    procedure btnQWLXSelClick(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    fFilter: TShareVehicleFilter;
    fInCityCode: string;
    fToCityCode: string;
    procedure SetFilter(const Value: TShareVehicleFilter);
  public
    property Filter: TShareVehicleFilter read fFilter write SetFilter;
  end;

function GetShareVehicleFilter(_filter: TShareVehicleFilter): Boolean;

implementation

{$r *.dfm}

var
  FrmShareVehicleFilter: TFrmShareVehicleFilter;

function GetShareVehicleFilter(_filter: TShareVehicleFilter): Boolean;
begin
  if not Assigned(FrmShareVehicleFilter) then
    FrmShareVehicleFilter := TFrmShareVehicleFilter.Create(Application);
  FrmShareVehicleFilter.Filter := _filter;
  Result := FrmShareVehicleFilter.ShowModal = mrOk;
end;

{ TFrmShareVehicleFilter }

procedure TFrmShareVehicleFilter.btnClearQWLXClick(Sender: TObject);
begin
  edtQiWangLiuXiang.Text := '';
  fToCityCode := '';
end;

procedure TFrmShareVehicleFilter.btnQWLXSelClick(Sender: TObject);
var
  names, codes: string;
begin
  if (PromptCities(edtQiWangLiuXiang.Text, names,
    codes, [asoAllowProvince, asoAllowCity,
      asoIncludeProvinceIDOfCity,
      asoCombineProvinceCityID])) then
  begin
    edtQiWangLiuXiang.Text := names;
    fToCityCode := codes;
  end;  
end;

procedure TFrmShareVehicleFilter.btnOKClick(Sender: TObject);
begin
  GetControlData(Panel1, fFilter);
  fFilter.QiWangLiuXiang := edtQiWangLiuXiang.Text;
  fFilter.InCityNames := edtDangQianWeiZhi.Text;
  fFilter.InCityCode := fInCityCode;
  fFilter.ToCityCode := fToCityCode;
  case cbbLocate.ItemIndex of
    0: fFilter.Locatable := nbNull;
    1: fFilter.Locatable := nbTrue;
    2: fFilter.Locatable := nbFalse;
  end;
  ModalResult := mrOk;
end;

procedure TFrmShareVehicleFilter.btnDQCSSelClick(Sender: TObject);
var
  names, codes: string;
begin
  if (PromptCities(edtDangQianWeiZhi.Text, names,
    codes, [asoAllowCity])) then
  begin
    edtDangQianWeiZhi.Text := names;
    fInCityCode := codes;
  end;  
end;

procedure TFrmShareVehicleFilter.btnClearDQWZClick(Sender: TObject);
begin
  edtDangQianWeiZhi.Text := '';
  fInCityCode := '';
end;

procedure TFrmShareVehicleFilter.FormCreate(Sender: TObject);
begin
  cbbCheZhang.Items.Delimiter := ';';
  cbbCheZhang.Items.DelimitedText := gc_CheChang;
  cbbCheZhang.Items.Insert(0, '');
  cbbDunWei.Items.Delimiter := ';';
  cbbDunWei.Items.DelimitedText := gc_DunWei;
  cbbDunWei.Items.Insert(0, '');
  cbbTuoGuaLunZhou.Items.Delimiter := ';';
  cbbTuoGuaLunZhou.Items.DelimitedText := gc_TuoGuaJiLunZhou;
  cbbTuoGuaLunZhou.Items.Insert(0, '');
  cbbHuoXiangJieGou.Items.Delimiter := ';';
  cbbHuoXiangJieGou.Items.DelimitedText := gc_HuoXiangJieGou;
  cbbHuoXiangJieGou.Items.Insert(0, '');
  cbbTeShuGongNeng.Items.Delimiter := ';';
  cbbTeShuGongNeng.Items.DelimitedText := gc_TeShuGongNeng;
  cbbTeShuGongNeng.Items.Insert(0, '');
  cbbChangShangPinPai.Items.Delimiter := ';';
  cbbChangShangPinPai.Items.DelimitedText := gc_ChangShangPinPai;
  cbbChangShangPinPai.Items.Insert(0, '');
end;

procedure TFrmShareVehicleFilter.SetFilter(
  const Value: TShareVehicleFilter);
begin
  fFilter := Value;
  fInCityCode := Value.InCityCode;
  fToCityCode := Value.ToCityCode;
  SetControlData(Panel1, Value);
  edtQiWangLiuXiang.Text := Value.QiWangLiuXiang;
  edtDangQianWeiZhi.Text := Value.InCityNames;
  case Value.Locatable of
    nbTrue: cbbLocate.ItemIndex := 1;
    nbFalse: cbbLocate.ItemIndex := 2;
    nbNull: cbbLocate.ItemIndex := 0;
  end;
end;

end.
